package com.dycong.common.IO.netty.ssl.client;

import com.dycong.common.IO.netty.first.EchoClientHandler;
import io.netty.channel.ChannelInitializer;
import io.netty.channel.socket.SocketChannel;
import io.netty.handler.codec.string.StringDecoder;
import io.netty.handler.codec.string.StringEncoder;
import io.netty.handler.ssl.SslHandler;

import javax.net.ssl.SSLEngine;


/**
 * Created by dycong on 2017/4/5.
 */
public class SecureClientInitializer extends ChannelInitializer<SocketChannel> {

    public void initChannel(SocketChannel ch) throws Exception {
        SSLEngine sslEngine = SecureSocketSslContextFactory.getClientContext().createSSLEngine();
        sslEngine.setUseClientMode(true);
            ch.pipeline().addLast("ssl", new SslHandler(sslEngine))
                .addLast(new EchoClientHandler())
                .addLast(new StringDecoder())
                .addLast(new StringEncoder());
    }
}
